home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Chat / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  3.8 KB  |  146 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        Help.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1991 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* This file contains some sample code for handling dynamic balloon help.  The
  12. ** assumption here, which is valid for DTS.Chat, is that you have controls in
  13. ** the window content, and these controls need balloon help.  Since a DTS.Chat
  14. ** document window consists of two TextEdit controls, this assumption works quite
  15. ** well.  The code walks the control list, looking at the bounding rect of the
  16. ** control.  If the cursor is within that rect, it shows a belloon with the
  17. ** associated help text. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  27. #include "App.protos.h"        /* Get the prototypes for application.            */
  28.  
  29. #ifndef __BALLOONS__
  30. #include <Balloons.h>
  31. #endif
  32.  
  33. #ifndef __PROCESSES__
  34. #include <Processes.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /*****************************************************************************/
  44. /*****************************************************************************/
  45.  
  46.  
  47.  
  48. #pragma segment Main
  49. void    DynamicBalloonHelp(void)
  50. {
  51.     WindowPtr            window, oldPort;
  52.     ProcessSerialNumber    cpsn, fpsn;
  53.     FileRecHndl            frHndl;
  54.     Point                mouseLoc, tip;
  55.     ControlHandle        ctl;
  56.     Rect                rct;
  57.     short                part, message, pos;
  58.     HMMessageRecord        helpMessage;
  59.     Boolean                procsSame;
  60.     TEHandle            teHndl;
  61.     static short        lastMessage;
  62.     static short        position[4] = {5, 6, 2, 1};
  63.  
  64.     if (gSystemVersion < 0x0700) return;
  65.         /* The system can't support balloons. */
  66.  
  67.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  68.         lastMessage = 0;
  69.         return;
  70.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  71.  
  72.     HMGetBalloonWindow(&window);
  73.     if (!window)
  74.         lastMessage = 0;
  75.             /* There is no balloon currently, so there is no last message. */
  76.  
  77.     tip = mouseLoc = GetGlobalMouse();
  78.     part = FindWindow(mouseLoc, &window);
  79.     if ((window != FrontWindow()) || (part != inContent)) {
  80.         lastMessage = 0;
  81.         return;
  82.     }        /* We aren't over the content of the front window, so leave. */
  83.  
  84.     GetCurrentProcess(&cpsn);
  85.     GetFrontProcess(&fpsn);
  86.     SameProcess(&cpsn, &fpsn, &procsSame);
  87.     if (!procsSame) {
  88.         lastMessage = 0;
  89.         return;
  90.     }        /* We aren't the front process, so leave. */
  91.  
  92.     GetPort(&oldPort);
  93.     frHndl = (FileRecHndl)GetWRefCon(window);
  94.     SetPort(window);
  95.     GlobalToLocal(&mouseLoc);
  96.  
  97.     ctl = ((WindowPeek)window)->controlList;
  98.     while (ctl) {
  99.         rct = (*ctl)->contrlRect;
  100.         if (PtInRect(mouseLoc, &rct)) break;
  101.         ctl = (*ctl)->nextControl;
  102.     }        /* Find the control that we are over. */
  103.  
  104.     message = 0;
  105.     if (ctl) {
  106.         teHndl = (TEHandle)GetCRefCon(ctl);
  107.         if (teHndl == (*frHndl)->d.doc.inBox)
  108.             message = 2;
  109.         if (teHndl == (*frHndl)->d.doc.outBox)
  110.             message = 4;
  111.     }
  112.  
  113.     if (message) {
  114.         if ((*frHndl)->connect.connected)
  115.             --message;
  116.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  117.             lastMessage = message;
  118.             helpMessage.hmmHelpType             = khmmStringRes;
  119.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  120.             helpMessage.u.hmmStringRes.hmmIndex = message;
  121.             LocalToGlobalRect(&rct);
  122.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  123.             if (tip.h > (rct.left + rct.right) / 2)
  124.                 ++pos;
  125.             pos = position[pos];
  126.             SetOrigin(0, 0);
  127.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  128.         }
  129.     }
  130.     else {
  131.         if (lastMessage)
  132.             HMRemoveBalloon();
  133.         lastMessage = 0;
  134.     }
  135.  
  136.     SetOrigin(0, 0);
  137.         /* It is expected that you will modify this code, so I went ahead and set the origin
  138.         ** back to 0,0, in case your modifications alter it.  Currently, I don't change it,
  139.         ** but you might someday. */
  140.  
  141.     SetPort(oldPort);
  142. }
  143.  
  144.  
  145.  
  146.